package cloud.tianai.ram.policy.demo;

import cloud.tianai.ram.policy.common.model.dto.Action;
import cloud.tianai.ram.policy.common.model.dto.Condition;
import cloud.tianai.ram.policy.common.handler.ConditionHandler;
import cloud.tianai.ram.policy.common.handler.ConditionHandlerManager;
import cloud.tianai.ram.policy.common.model.dto.TypeDefinition;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class TestConditionHandler implements ConditionHandler {
    @Override
    public boolean match(Condition condition, ConditionHandlerManager conditionHandlerManager, Action action) {
        String operationType = condition.getOperationType();
        String key = condition.getKey();
        List<String> valueList = condition.getValueList();
        String ip = "127.0.0.1";
        return valueList.contains(ip);
    }

    @Override
    public boolean support(Condition condition) {
        return support(condition.getOperationType());
    }

    @Override
    public boolean support(String type) {
        return "ip".equalsIgnoreCase(type);
    }

    @Override
    public List<TypeDefinition> listSupportTypes() {
        return null;
    }

}
